﻿#include "ChargeGunNotConnect.h"
#include "ui_chargegunnotconnect.h"
#include "Global.h"

ChargeGunNotConnect::ChargeGunNotConnect(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::ChargeGunNotConnect)
{
    ui->setupUi(this);
    time = new QLabel(ui->frameBottom);
    time->setGeometry(10, 10, 200, 40);
    time->setStyleSheet("QLabel{font: 20px; color: rgb(25, 25, 112);}");
    signal = new QLabel(ui->frameBottom);
    signal->setGeometry(700, 18, 41, 22);
    signal->setStyleSheet("QLabel{background-color:transparent;}");

    QDir dir(IMAGE_PATH);
    if(dir.exists())
    {
        ui->frameTop->setStyleSheet(LOGO_STY);
    }

    countdown = new CountDownTime(ui->frameMid);
    countdown->setGeometry(710, 10, 30, 40);
    countdown->mysetText("60");
    countdown->hide();
    connect(this->countdown, SIGNAL(CoundDownTimeisOver()), this, SLOT(countdownOver()));
    connect(&Without_operation, SIGNAL(timeout()), this, SLOT(ComeBack_WaitUsePage()));
    connect(stackLayout, SIGNAL(currentChanged(int)), this, SLOT(Withou_operation_timer(int)));
    for(int i=0; i<GUN_AMOUNT; i++)
    {
        //connect(&Refreash_Thread[i], SIGNAL(putInCharger(int)), this, SLOT(handle_put_in_charge(int)));
    }
//    ui->labelRestTime->hide();
//    ui->second->hide();
}

ChargeGunNotConnect::~ChargeGunNotConnect()
{
    delete ui;
}

void ChargeGunNotConnect::Withou_operation_timer(int current)
{
    if(current == chargeGunNotConnectPage)
    {
        ui->_focus_gun_->setText(QString::number(focus_gun_));
        Without_operation.start(10000);
    }
    else
    {
        Without_operation.stop();
    }
}

void ChargeGunNotConnect::handle_put_in_charge(int gun_no)
{
    if (gun_no < GUN_AMOUNT)
    {
        focus_gun_ = gun_no + 1;
        stackLayout->setCurrentIndex(GUN_STATE[gun_no].Page);
    }
}

void ChargeGunNotConnect::countdownOver()
{
    /*待完成*/
    countdown->CountDownStop();
}

void ChargeGunNotConnect::ComeBack_WaitUsePage()
{
    Back_Stand_By();
}

void ChargeGunNotConnect::on_CancelChargingButton_clicked()
{
//    stackLayout->setCurrentIndex(chargeGunNotNotConnectPage);
#if (GUN_AMOUNT != 1)
    Init_Focus();
#else
    focus_gun_ = 0;//焦点初始化
    stackLayout->setCurrentIndex(ChooseGunPage);
#endif
}
